#include "pMailbox.h"


void createMessage(pMessage_t* message, char* messageText, int vAddr,
		int offset, int byteAmmount, char* fileName, char* stringParam)
{
	message->messageText = messageText;
	message->vAddr = vAddr;
	message->byteAmmount = byteAmmount;
	message->offset = offset;
	message->fileName = fileName;
	message->stringParam = stringParam;
}

void killMessage(pMessage_t* message)
{
	FREE(message->messageText);
	FREE(message->fileName);
	FREE(message->stringParam);
	FREE(message);
}

void mbox_init(blockingQueue* queue){
	//queue = malloc(sizeof(blockingQueue));
	initBQueue(queue);
}
void mbox_enqueue(blockingQueue* mbox, pMessage_t* message)
{
	llNode * node = malloc(sizeof(llNode));
	node->data = message;
	bqueueEnqueue(mbox,node);
}
pMessage_t* mbox_dequeue(blockingQueue* mbox){
	llNode* node = bqueueDequeue(mbox);
	pMessage_t* res = node->data;
	FREE(node);
	return res;
}
void mbox_clean(blockingQueue* mbox){
	while(mbox->list->size > 0){
		pMessage_t* msg = mbox_dequeue(mbox);
		killMessage(msg);
	}
}
void mbox_kill(blockingQueue* mbox){
	mbox_clean(mbox);
	killBQueue(mbox);
}
